﻿using System;
using System.Collections.Generic;
using Alone.GameObjects;
using Alone.GameObjects.Enemy;
using Microsoft.Xna.Framework;

namespace Alone.EnemyStates
{
	class KillingState : EnemyState, IEnemyState
	{
		Matrix rotationMatrix;
		Vector3 movementVelocity;
		
		public KillingState() { }

		public override void doAI(Enemy enemy, List<Enemy> enemies, List<BasePlayer> players)
		{
			BasePlayer player = players[0];
			float distance = float.MaxValue;

            // Animate the enemy to bite the player
			if (enemy.AnimationController.AnimationClip.Name.Equals("Walk"))
			{
				enemy.AnimationController.CrossFade(enemy.SkinnedModel.AnimationClips["Bite1"], TimeSpan.FromSeconds(0.2));
				enemy.AnimationController.Speed = 1f;
			}
			
			foreach (BasePlayer p in players) // Check whitch player is closest (Whitch one to kill)
			{
				if (Vector3.Distance(enemy.Position, p.Position) < distance)
				{
					player = p;
				}
			}
			enemy.Rotation.Y = TurnToFace(enemy.Position, player.Position, enemy.Rotation.Y, 1f);
		}
            
		public override float evaluate(Enemy enemy, List<Enemy> enemies, BasePlayer player)
		{
            // IF the enemy is very close to the player, KILL
			return isNearPlayer(enemy.Position, player.Position) + isVeryNearPlayer(enemy.Position, player.Position);
		}
	}
}
